
<div class="center">
	<div class="home">
    	<div class="home_left">
        	<?php echo $this->partial('tuan/menu.phtml',array('uCount' => $this->uCount,'menuId'=>$this->menuId,'user'=>$this->user)); ?>
        </div>
    	<div class="home_right">
			<div class="waybill">
				<div class="wbweizhi">
                	 <a href="/member/home">我的个人中心</a><span>&gt;</span><a href="/member/waybill">我的国际运单</a><span>&gt;</span>运单详情
                </div>
                <? switch ($this->waybill->Status){
                    case Application_Model_wayBillItem::STATUS_WaitPay:
                ?>
                    <div class="wbtop">
                        <div class="toptishi">
                            <h1>当前运单状态：待付款</h1>
                            <p>完成您的运单还差一步，请立即支付，请在48小时内付清款项，否则运单会自动取消。</p>
                        </div>                    
                        <div class="topcz">
                            <ul>
                                
                                <li><a class="cx" href="<?php echo "/member/waybill/?oper=cancel&id=".($this->waybill->id);?>">撤销订单</a></li>
                            </ul>
                        </div>                    
                    </div>                 
                <?
                        break;
                    case Application_Model_wayBillItem::STATUS_Processing:
                ?>
                    <div class="wbtop">
                        <div class="toptishi">
                            <h1>当前运单状态：己付款，等待受理</h1>
                            <p>正在等待受理，一旦受理完成，将不能撤消运单</p>
                        </div>                    
                        <div class="topcz">
                            <ul>
                                <li><a class="cx" href="<?php echo "/member/waybill/?oper=cancel&id=".($this->waybill->id);?>">撤销订单</a></li>
                            </ul>
                        </div>                    
                    </div>           
                <?
                        break;
                    case Application_Model_wayBillItem::STATUS_Confrimed:
                ?>
                        <div class="wbtop">
                            <div class="toptishi">
                                <h1>当前运单状态：已经受理</h1>
                                <p>您的运单已受理,正在准备为您发货，请稍候。</p>
                            </div>
                            
                        </div>                
                <?
                        break;
                    case Application_Model_wayBillItem::STATUS_Sended:
                ?>
                        <div class="wbtop">
                            <div class="toptishi">
                                <h1>当前运单状态：运单正在发送途中...</h1>
                                <p>您的运单已发送，请耐心等待，如有疑问请联系悠奇客服。</p>
                            </div>
                            
                        </div>                
                <?
                        break;
                    case Application_Model_wayBillItem::STATUS_Complated:
                ?>
                        <div class="wbtop">
                            <div class="toptishi">
                                <h1>当前运单状态：已确认收货</h1>
                                <p>如果没有收到货，或收到货后出现问题，请联系悠奇客服。</p>
                            </div>
                            
                        </div>                
                <?
                        break;
                    default :
                ?>
                <div class="wbtop">
                	<div class="toptishi">
                        <h1 class="hong">当前运单状态：<?= $this->waybill->getStatusName() ?></h1>
                        <p>您的运单可能存在敏感物品未能出关，如有疑问请联系悠奇客服。</p>
                    </div>
                </div>          
                <?
                        break;
                }
                ?>
                <div class="wuliuxinxi">
                    <div class="wayname"><h2>物流信息</h2></div>
                    <div class="wuliuinfo">
                        <table>
                            <tr>
                                <td class="l1">仓库号：</td>
                                <td class="l2">
                                  <?php echo $this->userxx->storeno;?>(ID:<?=$this->userxx->Id ?> 用户名:<?=$this->userxx->email ?>)</td>
                                <td class="l1">国家：</td>
                                <td class="l2"><?= $this->waybill->CityBy->Name ?>(<?= $this->waybill->CityBy->ename ?>)</td>
                            </tr>                            
                            <tr>
                                <td class="l1">悠奇运单编号：</td>
                                <td class="l2"><?php echo $this->waybill->billNo;?></td>
                                <td class="l1">提交时间：</td>
                                <td class="l2"><?php echo $this->waybill->dateCreated?></td>
                            </tr>
                            <tr>
                                <td class="l1">是否去掉包装</td>
                                <td class="l2"><?= $this->waybill->IsNoSkin?'去掉':'否' ?></td>
                                <td class="l1">是否真空包装</td>
                                <td class="l2"><?= $this->waybill->IsCompress?'要真空':'否' ?></td>
                            </tr>
                            <tr>
                                <td class="l1">运送方式：</td>
                                <td class="l2"><?php echo $this->waybill->ExpressBy->Name?></td>
                                <td class="l1">物品净重：</td>
                                <td class="l2"><?= $this->waybill->productWeight ?>g</td>
                            </tr>
                            <tr>
                                <td class="l1">是否去掉吊牌</td>
                                <td class="l2"><?= $this->waybill->IsNoLogo?'去掉':'否' ?></td>
                                <td class="l1"><? if($this->waybill->AgentBy){ ?><?= $this->waybill->AgentBy->Name ?>单号：<? } ?></td>
                                <td class="l2"><?= $this->waybill->AgentNo ?></td>
                            </tr>
                            <tr>
                                <td class="l1">预付重量：</td>
                                <td class="l2"><?= $this->waybill->Weight ?>g<span><?= $this->waybill->IsVolume?'(按预估体积重量)':'(按预估包裹重量)' ?> </span></td>
                                <td class="l1">预付金额：</td>
                                <td class="l2">
                                    <? if($this->waybill->Status == Application_Model_wayBillItem::STATUS_WaitPay){
                                    ?>
                                    <form action="/tuan/editprice/wayId/<?= $this->waybill->Id ?>">
                                        <?= $this->formText('shipMoney',$this->waybill->ShipMoney) ?><input type="submit" value="修改价格" />
                                    </form>
                                    <?
                                    }else{
                                       echo '￥'.$this->waybill->ShipMoney;
                                    }?>
                                </td>  
                            </tr>
                            <tr>
                                <td class="l1">收货地址：</td>
                                <td colspan="3" class="l3"><?php echo $this->waybill->consignee.'，'.$this->waybill->conTel.'，'.$this->waybill->conAdd.'，'.$this->waybill->conPostCode;?></td>
                            </tr>
                        </table>
                    </div>
                    
                    <div class="wayname"><h2>运单发货信息</h2></div>
                    <div class="fahuo">
                    	<table>
                        	<tr>
                            	<td class="l1"><?= $this->waybill->ShipTypeBy->Name ?>单号：</td>
                            	<td class="l2"><?= $this->waybill->logistics?$this->waybill->logistics :'<i>待定</i>' ?></td>
                            	<td class="l1">发货日期：</td>
                            	<td class="l2"><?= $this->waybill->DateSend?$this->waybill->DateSend:'<i>未发货</i>' ?> </td>
                            </tr>
                        	<tr>
                            	<td class="l1">实际结算重量：</td>
                                <td class="l2">
                             <? if($this->waybill->LastWeight || $this->waybill->LastVolumeWeight){
                                    echo ($this->waybill->IsVolume?$this->waybill->LastVolumeWeight:$this->waybill->LastWeight).'g';
                                    echo '<span>'.($this->waybill->IsVolume?' (按体积重量)':'（按实际重量）').'</span>';
                                }else{
                                    echo '<i>等待发包测量</i>';
                                }
                                ?>
                                </td>
                            	<td class="l1">实际支付金额：</td>
                            	<td class="l2"><em><?= $this->waybill->LastMoney?'￥'.$this->waybill->LastMoney:'<i>待定</i>' ?></em><?= $this->waybill->RefundMoney?"<strong>(退款￥". $this->waybill->RefundMoney .")</strong>":'' ?> </td>
                            </tr>
                        </table>
                    </div>
                    <div class="wayname"><h2>订单操作</h2></div>
                    <div class="fahuo">
                        <table>
                            <tr>
                                <td>操作流程：</td>
                                <td>用发待付款--> 确认受理 --> 确认发货 --> 订单完成</td>
                            </tr>
                            <tr>
                                <td>操作</td>
                                <td>
                                    <? if($this->waybill->Status == Application_Model_wayBillItem::STATUS_Processing){ ?>
                                    <form action="/tuan/accept/wayId/<?= $this->waybill->Id ?>"><input type="submit" value="确认受理" /></form>
                                    <? }else if($this->waybill->Status == Application_Model_wayBillItem::STATUS_Confrimed){ ?>
                                    <form id="sendform" action="/tuan/send/wayId/<?= $this->waybill->Id ?>">
                                        <table style="width:600px;">
                                            <tr>
                                                <td>实际重量</td>
                                                <td><?= $this->formText('lastWeight') ?>g</td>
                                                <td>体积重量</td>
                                                <td><?= $this->formText('lastVolumeWeight') ?>g</td>
                                            </tr>
                                            <tr>
                                                <td>实际价格</td>
                                                <td><?= $this->formText('lastMoney')  ?>元 <input type="button" id="cult" value="计算"></td>
                                                <td>退款金额</td>
                                                <td><?= $this->formText('refundMoney',0) ?>元</td>
                                            </tr>
                                            <tr>
                                                <td>发货代理商</td>
                                                <td><select name="agentId">
                                                        <option value="1" selected="true">递四方</option>
                                                        <option value="2">圣达</option>
                                                        <option value="3">互联易</option>
                                                        <option value="4">嘉泰</option>
                                                    </select>
                                                </td>
                                                <td>代理商单号</td>
                                                <td><?= $this->formText('agentNo') ?></td>
                                            </tr>
                                        </table>
                                        <input type="submit" value="  发  货    " /></form>
                                    <br/>
                                    <? }else if($this->waybill->Status == Application_Model_wayBillItem::STATUS_Sended){ ?>
                                    <form action="/tuan/editshipno/wayId/<?= $this->waybill->Id ?>">
                                        <table style="width:600px;">
                                            <tr>
                                                <td>物流公司</td>
                                                <td>
                                                    <?= $this->formSelect('shipType',$this->waybill->ShipType,null,array(1=>'Fedex',2=>'DHL',3=>'EMS',4=>'邮政小包',5=>'UPS',151=>'澳大利亚EMS',7=>'新加坡EMS',122=>'香港邮政',0=>'无')) ?>
                                                </td>
                                                <td>物流单号</td>
                                                <td><?= $this->formText('logistics',$this->waybill->logistics) ?></td>
                                            </tr>
                                            <tr>
                                                <td>成本价</td>
                                                <td><?= $this->formText('costMoney',$this->waybill->CostMoney) ?></td>
                                            </tr>
                                        </table>
                                        <input type="submit" value="  修改  " /></form>
                                    <? } ?>
                                </td>
                            </tr>
                        </table>
                        <div id="cost">
                        <p style="background-color:#ccc">成本报价,重量：<?= $this->waybill->getCurrentWeight() /1000 ?>kg</p>
                        <table>
                            <tr>
                                <td>快递方式</td>
                                <td>代理公司</td>
                                <td>发货渠道</td>
                                <td>价格起始档</td>
                                <td>总价</td>
                            </tr>
                            <? foreach ($this->costs as $item){ ?>
                            <tr>
                                <td><?= $item->getExpress()->Name ?></td>
                                <td><?= $item->getAgentCompany()->Name ?></td>
                                <td><?= $item->getChannel()->Name ?></td>
                                <td><?= $item->weight ?></td>
                                <td style="color:red"><?= $item->getMoney($this->waybill->getCurrentWeight()) ?></td>
                            </tr>
                            <? } ?>
                        </table>                        
                        </div>    
                        <div id="dsf">
                            成本数据加载中...
                        </div>
                            
                    </div>
                    <div class="wayname"><h2>物流跟踪</h2></div>
                    <div class="genzong">
                        <? if(count($this->waybill->getLogisticsItems())==0 && $this->waybill->Logistics ==NULL){
                            echo '<div class="mingxi"> 暂无物流跟踪信息</div>';
                        } ?>
                        <table>
                            <?foreach($this->waybill->getLogisticsItems() as $item){ ?>
                            <tr>
                                <td class="gz"><?= $item->OpDate ?></td>
                                <td><?= $item->OpRemark ?></td>
                            </tr>
                            <? } ?>
                        </table>                                
                        <?
                        if($this->waybill->Logistics != NULL && $this->waybill->Logistics!='')
                            {
                        ?>
                    	<table>
                        	<tr>
                                <td> 
                            <div class="mingxi">
                                    物流状态加载中...
                            </div>
                            <script type="text/javascript">
                            $(function(){
                                $.post('/member/getexpress', {'id':<?= $this->waybill->Id ?>,'type':'2'}, function(data){
                                    if(data.isUrl!="0"){
                                        var html = '<iframe name="kuaidi100" src="'+data.content+'" width="600" height="380" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>';
                                        $('.mingxi').html(html);
                                    }else{
                                        $('.mingxi').html(data.content);
                                    }

                                }, 'json');
                            })
                            </script>
                                </td>
                            </tr>
                        </table>
                        <? } ?>
                        <form action="/tuan/addlog/wayId/<?= $this->waybill->Id ?>">
                        <table>
                            <tr>
                                <td>添加物流记录</td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>操作时间</td>
                                <td><?= $this->formText('opDate',date('Y-m-d H:i:s'),array('style'=>'width:200px')) ?></td>
                            </tr>
                            <tr>
                                <td>操作内容</td>
                                <td><?= $this->formText('opRemark',null,array('style'=>'width:500px')) ?></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><input type="submit" value="添加物流记录" /> </td>
                            </tr>
                        </table>
                        </form>
                        
                    </div>
                </div>
                <div class="kucunlist">
                    <div class="wayname"><h2>运单货物详情</h2></div>
                    <div class="qingdan">
                    	<table>
                            <tr>
                            	<th class="o1">仓库单号</th>
                                <th class="o2">名称</th>
                                <th class="o3">重量(g)</th>
                                <th class="o4">体积重量</th>
                            </tr>
                            <?php 
                            $items=$this->waybill->storeItems();
                            if(!empty($items )){
                                //var_dump($items);
                                foreach ($items as $item){ ?>
                            
                            <tr>
                                <td class="o1"><?= substr($item->Barcode,3) ?></td>
                                <td class="o2">
                                    <div class="whpic">
                                         <a href="<?= $this->cdn ?><?= is_file('big'.$item->imageFile)?('/big'.$item->imageFile):($item->imageFile) ?>" target="_blank"><img src="<?= $item->Image ?>" alt="<?= $item->productName ?>" /></a>
                                    </div>
                                    <div class="whinfo">
                                        <h2> <a href="<?= $this->cdn ?><?= is_file('big'.$item->imageFile)?('/big'.$item->imageFile):($item->imageFile) ?>" target="_blank"><?php  echo $item->productName ?></a></h2>
                                        <div class="wh_add">
                                            <p>来自:<?php echo $item->intype; ?></p>
                                        </div>
                                    </div>
                                </td>
                                <td class="o3"><?php echo $item->weight;?></td>
                                <td class="o4"><?= $item->VolumeWeight?$item->VolumeWeight.'g':'(无)'; ?></td>
                            </tr>                            
                            <?php 

                                }
                            }
                            ?>
                           
                        </table>
                    </div>
                </div>
                
            </div>

        </div>
    </div>
</div>
<script type="text/javascript">
$(function(){
    $('#cult').click(function(){
        $(this).val('计算中..');
        var weight = $('#lastWeight').val();
        if(!weight){
            alert('请输入实际重量');
            return false;
        }
        if($('#lastVolumeWeight').val()!='' &&(parseInt($('#lastVolumeWeight').val()) > parseInt(weight)) ){
            weight = $('#lastVolumeWeight').val();
        }
        $.post('/tuan/cultfee', {'wayId':<?= $this->waybill->Id ?>,'weight':weight}, function(data){
            $('#cult').val('计算');
            $('#lastMoney').val(data.shipMoney);
            $('#refundMoney').val(data.refundMoney);
        }, 'json');
        $('#cost').html('运费试算中...');
        $.post('/tuan/feecost',{weight:weight,cityId:<?= $this->waybill->state?>,express:<?=$this->waybill->shipType ?>}, function(data){
            $('#cost').html(data);
        }, 'html');
        $('#dsf').html('正在获取递四方价格....');
        $.post('/tuan/feeapi', {weight:weight/1000,cityId:<?= $this->waybill->state?>,express:<?=$this->waybill->shipType ?>}, function(data){
            $('#dsf').html(data);
        }, 'html');
    });
    $.post('/tuan/feeapi', {weight:<?=$this->waybill->getCurrentWeight()/1000?>,cityId:<?= $this->waybill->state?>,express:<?=$this->waybill->shipType ?>}, function(data){
        $('#dsf').html(data);
    }, 'html');
    $('#sendform').submit(function(){
        var weight = $('#lastWeight').val();
        if(!weight){
            alert('请输入实际重量');
            return false;
        }       
        if(parseFloat($('#refundMoney').val())<0){
            alert('退款金额不能是负数');
            return false;
        }
    });
});
</script>